package com.bocai.eelly.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.FindToolsStockBean;
import com.bocai.eelly.utils.TimeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/30.
 */
public class FindToolsStockAdp extends BaseAdapter {
    private Context context;
    private List<FindToolsStockBean.DataEntity> dataEntities=new ArrayList<>();
    public FindToolsStockAdp(Context context,List<FindToolsStockBean.DataEntity> dataEntities) {
        this.context = context;
        this.dataEntities=dataEntities;
    }

    @Override
    public int getCount() {
        return dataEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return dataEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.find_stock_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvFindStockSize.setVisibility(View.GONE);
        viewHolder.tvFindStockMaterial.setVisibility(View.GONE);
        viewHolder.tvFindStockName.setText("设备名称："+dataEntities.get(position).getTitle());
        viewHolder.tvFindStockTitle.setText(dataEntities.get(position).getTitle());
        viewHolder.tvFindStockTime.setText(TimeUtils.getMonth(Long.parseLong(dataEntities.get(position).getTimeline())));
        viewHolder.tvFindStockNum.setText("数量："+dataEntities.get(position).getNum());
        return convertView;
    }


    class ViewHolder {
        @Bind(R.id.tv_find_stock_title)
        TextView tvFindStockTitle;
        @Bind(R.id.tv_find_stock_name)
        TextView tvFindStockName;
        @Bind(R.id.tv_find_stock_material)
        TextView tvFindStockMaterial;
        @Bind(R.id.tv_find_stock_price)
        TextView tvFindStockPrice;
        @Bind(R.id.tv_find_stock_time)
        TextView tvFindStockTime;
        @Bind(R.id.tv_find_stock_size)
        TextView tvFindStockSize;
        @Bind(R.id.tv_find_stock_num)
        TextView tvFindStockNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
